<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
      var myObject={
          foo:"bar",
          func:function(){
              var self=this;
              console.log("outer func:this.foo="+this.foo);//outer func:this.foo=bar
              console.log("outer func:self.foo="+self.foo);//outer func:self.foo=bar
         
          (function(){
           console.log("inner func:this.foo="+this.foo);//inner func:this.foo=undefined
           console.log("inner func:self.foo="+self.foo);//inner func:self.foo=bar
          }())
        }
      }
      myObject.func();
      //外部函数中，this和self都引用myObject,因此都可以访问foo
      //在内部匿名函数中，这不在指向myObject。因此,this.foo在内部函数未定义。而对局部变量self的引用仍然在范围内并且可以在那里访问
    </script>
</body>
</html>